<?php

namespace app\common\model\banxi\organization;

use app\common\model\common\BaseModel;
use think\Model;
use think\model\concern\SoftDelete;

/**
 * 机构等级配置
 */
class OrganizationData extends BaseModel
{
    use SoftDelete;

    protected $name = 'banxi_organization_data';

    protected $autoWriteTimestamp = true;

    protected $deleteTime = 'del';

    protected $defaultSoftDelete = 0;

    protected $append = [

    ];

    protected $type = [
        'id' => 'string',
        'del' => 'string',
        'createTime' => 'timestamp:Y-m-d H:i:s',
        'updateTime' => 'timestamp:Y-m-d H:i:s',
    ];

    //-----------------------------------------------------------------------------------
    //｜                                   获取器                                       ｜
    //-----------------------------------------------------------------------------------




    //-----------------------------------------------------------------------------------
    //｜                                   处理方法                                       ｜
    //-----------------------------------------------------------------------------------




    public function createData(array|Model $organization)
    {
        $organizationId = $organization['id'];
        if ($this->getExistOrganizationId($organizationId)) {
            return true;
        }
        return $this->save([
            'organizationId' => $organizationId
        ]);
    }

    public function getExistOrganizationId(string $organizationId)
    {
        return $this->where(['organizationId' => $organizationId])->count() > 0;
    }


    //-----------------------------------------------------------------------------------
    //｜                                   模型关联                                       ｜
    //-----------------------------------------------------------------------------------


}